package edu.ciee.tz.action;

import java.util.List;

import javax.annotation.Resource;

import edu.ciee.tz.dao.BuyerDAO;
import edu.ciee.tz.model.Buyer;
import edu.ciee.tz.model.Laiyuan;


public class BuyerAction {
	private int id;
	private String name;
	private String tele;
	
	private String tip;
	private List resultList;
	private BuyerDAO buyernDAO;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTele() {
		return tele;
	}
	public void setTele(String tele) {
		this.tele = tele;
	}
	public String getTip() {
		return tip;
	}
	public void setTip(String tip) {
		this.tip = tip;
	}
	public List getResultList() {
		return resultList;
	}
	public void setResultList(List resultList) {
		this.resultList = resultList;
	}
	public BuyerDAO getBuyernDAO() {
		return buyernDAO;
	}
	@Resource
	public void setBuyernDAO(BuyerDAO buyernDAO) {
		this.buyernDAO = buyernDAO;
	}
	
	public String forLuru() throws Exception {		
		return "success";		
	}
	public String insert(){
		try{
			Buyer b=new Buyer();
			b.setName(this.getName());
			b.setTele(this.getTele());
		
			this.getBuyernDAO().insert(b);
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String delete(){
		try{
			Buyer b=new Buyer();
			b.setId(this.getId());
			b.setName(this.getName());
			b.setTele(this.getTele());
			
			this.getBuyernDAO().delete(b);
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String forEdit(){
		return "success";
	}
	public String edit(){
		try{
			Buyer b=new Buyer();
			b.setId(this.getId());
			b.setName(this.getName());
			b.setTele(this.getTele());
			
			this.getBuyernDAO().update(b);
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String search(){
		try{
			Buyer b=new Buyer();
			b.setId(this.getId());
			b.setName(this.getName());
			b.setTele(this.getTele());
			
			this.setResultList(this.getBuyernDAO().search(b));
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
}
